﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace Jiuyong
{
	namespace ToolBox
	{
		public sealed partial class Core
		{
			public static List<Dictionary<int, string>> ReadXmlExcel(string xmlExcelFile)
			{
				var rv = new List<Dictionary<int, string>>();
				var fs = System.IO.File.Open(xmlExcelFile, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
				var xml = XDocument.Load(fs);
				var rs = from r in xml.Descendants("{urn:schemas-microsoft-com:office:spreadsheet}Row")
						  select r;

				foreach (var r in rs)
				{
					var ds = r.Descendants("{urn:schemas-microsoft-com:office:spreadsheet}Data").ToArray();
					//var row = new XElement(XName.Get("{urn:schemas-microsoft-com:office:spreadsheet}Row"));
					//var cell = new XElement(XName.Get("{urn:schemas-microsoft-com:office:spreadsheet}Cell"));
					//var att = new XAttribute(XName.Get("{urn:schemas-microsoft-com:office:spreadsheet}Type"), "String");
					//var data = new XElement(XName.Get("{urn:schemas-microsoft-com:office:spreadsheet}Data"));
					var ain = XName.Get("{urn:schemas-microsoft-com:office:spreadsheet}Index");
					var cs = r.Elements().ToArray();
					var index = 0;
					var vs = new Dictionary<int, string>();
					foreach (var n in r.Elements().ToArray())
					{
						var idx = n.Attribute("{urn:schemas-microsoft-com:office:spreadsheet}Index");
						if (null == idx)
						{
						}
						else
						{
							index = int.Parse(idx.Value) - 1;
						}
						var xdata = n.Element("{urn:schemas-microsoft-com:office:spreadsheet}Data");
						if (null == xdata)
						{

						}
						else
						{
							vs.Add(index, xdata.Value);
						}

						index++;
					}
					rv.Add(vs);
				}

				return rv;
			}
		}
	}

	public static partial class ToolBoxExtention
	{
		//internal static void ShowTextDialog(this System.Windows.Controls.Panel panel
		//    ,
		//    Action<string> dialogBack
		//    ,
		//    string defaultText = null
		//    ,
		//    IEnumerable<string> otherTexts = null
		//    ,
		//    string messageText = "输入字符串(_I)："
		//    )
		//{
		// 已经移动到公用库。
		//}
	}
}
